﻿using FirstFloor.ModernUI.Presentation;
using FirstFloor.ModernUI.Windows.Controls;
using FirstFloor.ModernUI.Windows.Navigation;
using LinnerToolkit.Desktop.ModernUI.Mvvm;
using LinnerToolkit.Desktop.ModernUI.Navigation;
using SimulationPTSystem.DAL;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace SimulationPTSystem.ViewModels
{
    public class TeamTrainingRecPageViewModel : ModernViewModelBase
    {
        private ObservableCollection<TeamTrainingRec> teamTrainingRecs;
        private TeamTrainingRec selectedTeamTrainingRec;

        public string TeamCode { get; set; }

        public string TeamName { get; set; }

        public ObservableCollection<TeamTrainingRec> TeamTrainingRecs { get => teamTrainingRecs; set => Set(ref teamTrainingRecs, value); }

        public TeamTrainingRec SelectedTeamTrainingRec { get => selectedTeamTrainingRec; set =>Set(ref selectedTeamTrainingRec,value); }

        public DateTime StartTime { get; set; }

        public DateTime EndTime { get; set; }

        public ICommand QueryCommand { get; }

        public ICommand DetailsCommand { get; }

        public TeamTrainingRecPageViewModel(IModernNavigationService navigationService) : base(navigationService)
        {
            StartTime = EndTime = DateTime.Now;

            QueryCommand = new RelayCommand(async (obj) =>
              {
                  TeamTrainingRecs = new ObservableCollection<TeamTrainingRec>(await SimulationPTDAL.GetTeamTrainingRecs(TeamCode, TeamName, StartTime, EndTime));
              });

            DetailsCommand = new RelayCommand((obj) =>
              {
                  if(SelectedTeamTrainingRec==null)
                  {
                      ModernDialog.ShowMessage("请先选择要查看的团队报告", string.Empty, System.Windows.MessageBoxButton.OK);
                      return;
                  }

                  // 查看报告
              });
        }
    }
}
